package org.simplesocket.simplenettymtbatis;

import lombok.Data;
import org.simplesocket.simplenettycore.config.ConfigLoader;
import org.simplesocket.simplenettycore.context.SimpleNettyContext;
import org.simplesocket.simplenettymtbatis.config.ConnectionPoolConfig;
import org.simplesocket.simplenettymtbatis.config.MybatisConfig;

@Data
public class SimpleNettyMybatisConfig implements ConfigLoader {
    
    private String configFile = "";
    
    private MybatisConfig configObject;
    
    private ConnectionPoolConfig connectionPoolConfig;
    
    private SimpleNettyMybatisConfig() {}
    
    @Override
    public void load(SimpleNettyContext simpleNettyContext) {
        SimpleNettyMybatisContext.init(simpleNettyContext,this);
    }
    
    public static Builder builder(){
        return new Builder();
    }
    
    public static class Builder{
        
        private final SimpleNettyMybatisConfig config;
        
        private Builder() {
            config = new SimpleNettyMybatisConfig();
        }
        
        public Builder configFile(String configFile){
            this.config.setConfigFile(configFile);
            return this;
        }
        
        public Builder connectionPoolConfig(ConnectionPoolConfig config){
            this.config.setConnectionPoolConfig(config);
            return this;
        }
        
        public Builder configObject(MybatisConfig configObject){
            this.config.setConfigObject(configObject);
            return this;
        }
        
        public SimpleNettyMybatisConfig build(){
            return config;
        }
        
    }
}
